import shopFn from "../api/shopping";

export default {
  namespaced: true,
  state: {
    products: [],
  },
  mutations: {
    SET_DATA(state, data) {
      state.products = data;
    },
    REDUCE_INVENTORY(state, item) {
      state.products.map((v) => {
        if (v.id == item.id) {
          v.inventory--;
        }
      });
    },
  },
  actions: {
    getData({ commit }) {
      shopFn.getProducts((data) => {
        commit("SET_DATA", data);
      });
    },
    // 库存减少
    reduceInventory({ commit }, item) {
      commit("REDUCE_INVENTORY", item);
    },
  },
  modules: {},
};
